package justcents.game.sticks;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;


public class EscolhaPalitosActivity extends Activity {

	@Override
	public void onCreate(Bundle icicle){
		super.onCreate(icicle);
		setContentView(R.layout.escolhapalitos);
		
		final Button btOk 			= (Button) findViewById(R.id.btOk);
		final RadioGroup rgRodada	= (RadioGroup) findViewById(R.id.rgEscolhaRodada);
		
		//Array Lista de Radio Button da Tela
		ArrayList<RadioButton> arRadioButton = new ArrayList<RadioButton>();
		
		arRadioButton.add((RadioButton) findViewById(R.id.rb1));
		arRadioButton.add((RadioButton) findViewById(R.id.rb2));
		arRadioButton.add((RadioButton) findViewById(R.id.rb3));
		
		//Pegando o parametro passado pela PartidaOffline
		Intent it = getIntent();
		if(it != null){
			Bundle params = it.getExtras();
			if(params != null){
				int nrTotalPalitos = params.getInt("nrTotalPalitos");
				for (int i = 0; i < nrTotalPalitos; i++) {
					RadioButton rbDisable = (RadioButton) arRadioButton.get(i);
					rbDisable.setVisibility(1);
				}
			}
		}
		
		//Click do Botão
        btOk.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				int checkedId = rgRodada.getCheckedRadioButtonId();
				int nrPalitos = 0;
				switch (checkedId) {
				case R.id.rb1:
					nrPalitos = 1;
					break;
				case R.id.rb2:
					nrPalitos = 2;
					break;
				case R.id.rb3:
					nrPalitos = 3;
					break;
				default:
					break;
				}
				Intent data = new Intent();
				data.putExtra("nrPalitos", nrPalitos);
				setResult(1, data);
				finish();
			}
		});
		
	}
	
}
